home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 236_01 / bawk.h < prev    next >
Text File  |  1989-06-05  |  8KB  |  300 lines

  1. /*
  2.     HEADER:        CUG236;
  3.     TITLE:        BAWK Include File;
  4.     DATE:        05/17/1987;
  5.     VERSION:    1.1;
  6.     FILENAME:    BAWK.H;
  7.     SEE-ALSO:    BAWK.C;
  8.     AUTHORS:    W. C. Colley III, B. Brodt;
  9. */
  10.  
  11. /*
  12.  * Shortened names of variables Fieldsep and Recordsep to keep them unique
  13.  * in their first six characters so that compilers with limited external
  14.  * name widths like Eco-C (CP/M version) don't choke.  Fixed minor glitch
  15.  * that causes some compilers to choke on function str_compile().  Added a few
  16.  * portability notes for some odd compilers.  Dealt with side effects of
  17.  * tolower() implemented as a macro.  Leaned on the host compiler's library
  18.  * for is....() functions.  Stripped BDS C hooks and some ugly hacks that
  19.  * they required.  Removed the dependency on sizeof(int) == sizeof(char *).
  20.  * 16 MAY 1987.     William C. Colley, III.
  21.  */
  22.  
  23. /* For 68000 */
  24. #define MPU68000    0
  25. #define MC68000        0
  26.  
  27. /*
  28.  * Portability Note:  8-bit systems often don't have the header files ctype.h
  29.  * and string.h.  If your compiler is one of these animals, uncomment the
  30.  * following #defines as required.
  31.  */
  32.  
  33. /*
  34. #define NO_CTYPE_H
  35. #define NO_STRING_H
  36. */
  37.  
  38. /*
  39.  * Portability Note:  Back in K & R days, standard library function malloc()
  40.  * was called alloc().    Some compilers (e.g. Eco-C under CP/M) haven't made
  41.  * the name change.  If yours is one of these compilers, uncomment the
  42.  * following #define:
  43.  */
  44.  
  45. /*
  46. #define malloc(p)    alloc(p)
  47. */
  48.  
  49. /*
  50.  * Portability Note:  The AZTEC C compilers handle the binary/text file
  51.  * dichotomy differently from most other compilers.  Uncomment the following
  52.  * pair of #defines if you are running AZTEC C:
  53.  */
  54.  
  55. /*
  56. #define getc(f)        agetc(f)
  57. #define putc(c,f)    aputc(c,f)
  58. */
  59.  
  60. #ifdef    NO_CTYPE_H
  61. int isalnum(), isalpha(), isdigit(), tolower();
  62. #else
  63. #include <ctype.h>
  64. #endif
  65.  
  66. #ifdef    NO_STRING_H
  67. int strncmp(), strlen();
  68. #else
  69. #include <string.h>
  70. #endif
  71.  
  72. /*
  73.  * Bawk constants and variable declarations.
  74.  */
  75. #ifdef BDS_C
  76. #define EXTERN /* */
  77. #else
  78.  
  79. #ifdef MAIN
  80. #define EXTERN /* */
  81. #else
  82. #define EXTERN extern
  83. #endif
  84.  
  85. #endif
  86.  
  87.  
  88. #define DEBUG 1 /* remove this line to compile without debug statements */
  89. #ifdef DEBUG
  90. EXTERN char Debug;        /* debug print flag */
  91. #endif
  92.  
  93. /*
  94.  * Table and buffer sizes
  95.  */
  96. #define MAXLINELEN    128    /* longest input line */
  97. #define MAXWORDS    (MAXLINELEN/2)    /* max # of words in a line */
  98. #define MAXWORKBUFLEN    4096    /* longest action or regular expression */
  99. #define MAXVARTABSZ    50    /* max # of symbols */
  100. #define MAXVARLEN    10    /* symbol name length */
  101. #define MAXSTACKSZ    40    /* max value stack length (for expressions) */
  102.  
  103.  
  104. /**********************************************************
  105.  * Current Input File variables                  *
  106.  **********************************************************/
  107. /*
  108.  * Current Input File pointer:
  109.  */
  110. EXTERN FILE *Fileptr;
  111. EXTERN char *Filename;        /* current input file name */
  112. EXTERN int Linecount;        /* current input line number */
  113. EXTERN int Recordcount;        /* record count */
  114. /*
  115.  * Working buffers.
  116.  */
  117. EXTERN char Linebuf[ MAXLINELEN ];    /* current input line buffer */
  118. EXTERN char *Fields[ MAXWORDS ];    /* pointers to the words in Linebuf */
  119. EXTERN int Fieldcount;            /* and the # of words */
  120. EXTERN char Workbuf[ MAXWORKBUFLEN ];    /* work area for C action and */
  121.                     /* regular expression parsers */
  122.  
  123. /**********************************************************
  124.  * Regular Expression Parser variables              *
  125.  **********************************************************/
  126. /*
  127.  * Tokens:
  128.  */
  129. #define CHAR    1
  130. #define BOL    2
  131. #define EOL    3
  132. #define ANY    4
  133. #define CLASS    5
  134. #define NCLASS    6
  135. #define STAR    7
  136. #define PLUS    8
  137. #define MINUS    9
  138. #define ALPHA    10
  139. #define DIGIT    11
  140. #define NALPHA    12
  141. #define PUNCT    13
  142. #define RANGE    14
  143. #define ENDPAT    15
  144.  
  145.  
  146. /**********************************************************
  147.  * C Actions Interpreter variables              *
  148.  **********************************************************/
  149. /*
  150.  * Tokens:
  151.  */
  152. #define T_STRING    'S'    /* primaries: */
  153. #define T_DOLLAR    '$'
  154. #define T_REGEXP    'r'
  155. #define T_CONSTANT    'C'
  156. #define T_VARIABLE    'V'
  157. #define T_FUNCTION    'F'
  158. #define T_SEMICOLON    ';'    /* punctuation */
  159. #define T_EOF        'Z'
  160. #define T_LBRACE    '{'
  161. #define T_RBRACE    '}'
  162. #define T_LPAREN    '('
  163. #define T_RPAREN    ')'
  164. #define T_LBRACKET    '['
  165. #define T_RBRACKET    ']'
  166. #define T_COMMA        ','
  167. #define T_ASSIGN    '='    /* operators: */
  168. #define T_MUL        '*'
  169. #define T_DIV        '/'
  170. #define T_MOD        '%'
  171. #define T_ADD        '+'
  172. #define T_SUB        '-'
  173. #define T_SHL        'L'
  174. #define T_SHR        'R'
  175. #define T_LT        '<'
  176. #define T_LE        'l'
  177. #define T_GT        '>'
  178. #define T_GE        'g'
  179. #define T_EQ        'q'
  180. #define T_NE        'n'
  181. #define T_NOT        '~'
  182. #define T_AND        '&'
  183. #define T_XOR        '^'
  184. #define T_IOR        '|'
  185. #define T_LNOT        '!'
  186. #define T_LAND        'a'
  187. #define T_LIOR        'o'
  188. #define T_INCR        'p'
  189. #define T_DECR        'm'
  190. #define T_IF        'i'    /* keywords: */
  191. #define T_ELSE        'e'
  192. #define T_WHILE        'w'
  193. #define T_BREAK        'b'
  194. #define T_CHAR        'c'
  195. #define T_INT        't'
  196. #define T_BEGIN        'B'
  197. #define T_END        'E'
  198. #define T_NF        'f'
  199. #define T_NR        '#'
  200. #define T_FS        ' '
  201. #define T_RS        '\n'
  202. #define T_FILENAME    'z'
  203.  
  204. #define PATTERN 'P'    /* indicates C statement is within a pattern */
  205. #define ACTION    'A'    /* indicates C statement is within an action */
  206.  
  207. /*
  208.  * Symbol table
  209.  */
  210. typedef struct variable {
  211.     char    vname[ MAXVARLEN ];
  212.     char    vclass;
  213.     char    vsize;
  214.     int    vlen;
  215.     char    *vptr;
  216. } VARIABLE;
  217.  
  218. EXTERN VARIABLE Vartab[ MAXVARTABSZ ], *Nextvar;
  219.  
  220. /*
  221.  * Value stack
  222.  */
  223. typedef union datum {
  224.     int    ival;
  225.     char    *dptr;
  226.     char    **ptrptr;
  227. } DATUM;
  228.  
  229. typedef struct item {
  230.     char    class;
  231.     char    lvalue;
  232.     char    size;
  233.     DATUM    value;
  234. } ITEM;
  235.  
  236. EXTERN ITEM Stackbtm[ MAXSTACKSZ ], *Stackptr, *Stacktop;
  237.  
  238. /*
  239.  * Symbol Table values
  240.  */
  241. #define ACTUAL        0
  242. #define LVALUE        1
  243. #define BYTE        1
  244. #define WORD        sizeof(DATUM)
  245.  
  246. /*
  247.  * Miscellaneous
  248.  */
  249. EXTERN char *Actptr;    /* pointer into Workbuf during compilation */
  250. EXTERN char Token;    /* current input token */
  251. EXTERN DATUM Value;    /* and its value */
  252. EXTERN char Saw_break;    /* set when break stmt seen */
  253. EXTERN char Where;    /* indicates whether C stmt is a PATTERN or ACTION */
  254. EXTERN char Fldsep[3];    /* field seperator */
  255. EXTERN char Rcrdsep[3]; /* record seperator */
  256. EXTERN char *Beginact;    /* BEGINning of input actions */
  257. EXTERN char *Endact;    /* END of input actions */
  258.  
  259. /**********************************************************
  260.  * Rules structure                      *
  261.  **********************************************************/
  262. typedef struct rule {
  263.     struct {
  264.         char *start;    /* C statements that match pattern start */
  265.         char *stop;    /* C statements that match pattern end */
  266.         char startseen; /* set if both a start and stop pattern */
  267.                 /* given and if an input line matched the */
  268.                 /* start pattern */
  269.     } pattern;
  270.     char *action;        /* contains quasi-C statements of actions */
  271.     struct rule *nextrule;    /* pointer to next rule */
  272. } RULE;
  273.  
  274. EXTERN RULE *Rules,        /* rule structures linked list head */
  275.     *Rulep;            /* working pointer */
  276.  
  277.  
  278. /**********************************************************
  279.  * Miscellaneous                      *
  280.  **********************************************************/
  281. /*
  282.  * Error exit values (returned to command shell)
  283.  */
  284. #define USAGE_ERROR    1    /* error in invokation */
  285. #define FILE_ERROR    2    /* file not found errors */
  286. #define RE_ERROR    3    /* bad regular expression */
  287. #define ACT_ERROR    4    /* bad C action stmt */
  288. #define MEM_ERROR    5    /* out of memory errors */
  289. /*
  290.  * Functions that are referenced across module boundaries:
  291.  */
  292. char *getmem(), *malloc();
  293. int act_compile(), alpha(), alphanum(), atoi(), dopattern(), getcharacter();
  294. int getline(), getoken(), instr(), isfunction(), iskeyword(), match();
  295. int parse(), pat_compile(), pop(), popint(), re_compile(), ungetcharacter();
  296. VARIABLE *findvar(), *addvar(), *decl();
  297. void assignment(), declist(), doaction(), endfile(), error(), expression();
  298. void fillmem(), free(), function(), movemem(), push(), pushint();
  299. void syntaxerror(), unparse();
  300.